﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Zocono.Infrastructure.Common;
using Zocono.WCS.Application.AppConfigureManage;
using Zocono.WCS.Domain.EntityInfo;
using Zocono.WCS.Infrastructure.ApllicationDto.WCSTaskDto;
using Zocono.WCS.Infrastructure.ApllicationDto;

namespace Zocono.WCS.WebApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ScRowInfoController : ControllerBase
    {
        private readonly ILogUtil _LogUtil;
        private readonly ScRowInfoApp _ScRowInfoApp;

        public ScRowInfoController(ILogUtil logUtil, ScRowInfoApp scRowInfoApp)
        {
            _LogUtil = logUtil;
            _ScRowInfoApp = scRowInfoApp;
        }

        [HttpPost]
        public async Task<HeaderResult<List<ScRowInfo>>> GetPagedScRowInfoAsync(QueryScRowInfoDto queryScRowInfo)
        {
            HeaderResult<List<ScRowInfo>> headerResult = new HeaderResult<List<ScRowInfo>>();
            try
            {
                PageDto<ScRowInfo> pageDto = await _ScRowInfoApp.GetPagedScRowInfoAsync(queryScRowInfo);
                headerResult.IsSucceed = true;
                headerResult.Result = pageDto.Result;
                headerResult.Total = pageDto.Total;
                headerResult.Message = "查询成功";
            }
            catch (Exception ex)
            {
                headerResult.IsSucceed = false;
                headerResult.Message = ex.ToString();
            }
            return headerResult;
        }
        [HttpPost]
        public async Task<HeaderResult<bool>> CreateScRowInfoAsync(ScRowInfo scRowInfo)
        {
            HeaderResult<bool> headerResult = new HeaderResult<bool>();
            try
            {
                var result = await _ScRowInfoApp.CreateScRowInfoAsync(scRowInfo);
                headerResult.IsSucceed = result;
                headerResult.Result = result;
                headerResult.Message = result ? "新增成功" : "新增失败";
            }
            catch (Exception ex)
            {
                headerResult.IsSucceed = false;
                headerResult.Message = ex.ToString();
            }
            return headerResult;
        }

        [HttpPost]
        public async Task<HeaderResult<bool>> ModifyScRowInfoAsync(ScRowInfo scRowInfo)
        {
            HeaderResult<bool> headerResult = new HeaderResult<bool>();
            try
            {
                var result = await _ScRowInfoApp.ModifyScRowInfoAsync(scRowInfo);
                headerResult.IsSucceed = result;
                headerResult.Result = result;
                headerResult.Message = result ? "修改成功" : "修改失败";
            }
            catch (Exception ex)
            {
                headerResult.IsSucceed = false;
                headerResult.Message = ex.ToString();
            }
            return headerResult;
        }

        [HttpPost]
        public async Task<HeaderResult<bool>> DeleteScRowInfoAsync(List<ScRowInfo> scRowInfoList)
        {
            HeaderResult<bool> headerResult = new HeaderResult<bool>();
            try
            {
                var result = await _ScRowInfoApp.DeleteScRowInfoAsync(scRowInfoList);
                headerResult.IsSucceed = result;
                headerResult.Result = result;
                headerResult.Message = result ? "删除成功" : "删除失败";
            }
            catch (Exception ex)
            {
                headerResult.IsSucceed = false;
                headerResult.Message = ex.ToString();
            }
            return headerResult;
        }
    }
}
